<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : cvTransformation.xsl
    Created on : 29. květen 2013, 22:20
    Author     : peka
    Description:
        Purpose of transformation follows.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="text" encoding="utf-8"/>

    <!-- TODO customize transformation rules 
         syntax recommendation http://www.w3.org/TR/xslt 
    
    -->
    <xsl:template match="/cv">
        
        \documentclass[english]{ecv}
        \usepackage{selinput}
        \SelectInputMappings{     
            aacute={á},             % of input encoding
            ecaron={ě},             % by a list of selcted glyphs
            Euro={€}                % see: http://partners.adobe.com/public/developer/en/opentype/glyphlist.txt
        }
        
        
        \ecvName{<xsl:value-of select="name/text()"/>}
        
        \begin{document}
        \begin{ecv}
        
        % Person Identification
        \ecvSec{\hypertarget{hypertarget:\ecvPerson}{\ecvPerson}}
        \ecvEPR{Name}   {<xsl:value-of select="name/text()"/>}
        \ecvEPR{Addresse}{<xsl:value-of select="address/street/text()"/> <xsl:value-of select="address/streetnumber/text()"/>\ecvNewLine
                         <xsl:value-of select="address/city/text()"/>, <xsl:value-of select="address/postnumber/text()"/>,
                         <xsl:value-of select="address/country/text()"/>}
        \ecvEPR{Telephone}{<xsl:value-of select="phone/text()"/>}
        \ecvEPR{E-Mail} {\ecvHyperEMail{<xsl:value-of select="email/text()"/>}}
        \ecvEPR{Date of birth}
                        {<xsl:value-of select="birthday/text()"/>}
          
        % Work Experiences              
        <xsl:apply-templates select="workexperiences"/> 
        
        % Education
        <xsl:apply-templates select="education"/>
        
        % Languages
        <xsl:apply-templates select="languages"/>

        % Abilities
        \ecvPageBreak
        <xsl:apply-templates select="skills"/>
        
        % Hobbies
        \ecvBSec{\hypertarget{hypertarget:Hobbies}{Hobbies}}
        <xsl:for-each select="interests/interest">
            \ecvEBSub{}{<xsl:value-of select="text()"/>}
        </xsl:for-each>
        
        
        \end{ecv}
        
        \end{document}
        \end
    </xsl:template>
    
    
    <xsl:template match="skills[count(./*) > 0]">
        \ecvBSec{\hypertarget{hypertarget:\ecvAbilities}{\ecvAbilities}}
        <xsl:for-each select="addtionalskill">
            \ecvEBSub{}{<xsl:value-of select="text()"/>}
        </xsl:for-each>
    </xsl:template>
    
    <xsl:template match="languages">
        \ecvBSec{\hypertarget{hypertarget:\ecvLanguages}{\ecvLanguages}}
        <xsl:for-each select="language">
            \ecvEBSub{}{\ecvBold{<xsl:value-of select="name/text()"/>}\ecvNewLine
                Degree: <xsl:value-of select="level/text()"/> 
                <xsl:apply-templates select="certificate"/>
                }\ecvNewLine
        </xsl:for-each>
    </xsl:template>

    <xsl:template match="certificate[count(./text()) > 0]">
        Certificate: <xsl:value-of select="text()"/> \ecvNewLine
    </xsl:template>
  
    
    <xsl:template match="education">
        \ecvBSec{\hypertarget{hypertarget:\ecvEducation}{\ecvEducation}}
        <xsl:for-each select="school">
            \ecvEFR{Period}{<xsl:value-of select="from/text()"/>--<xsl:value-of select="to/text()"/>}
            <xsl:apply-templates select="degree"/>
            \ecvENR{Institute}
                {<xsl:value-of select="name/text()"/>}
            \ecvENR{Field}
                {<xsl:value-of select="field/text()"/>}
            <xsl:apply-templates select="note"/>
            
        </xsl:for-each>
    </xsl:template>
    
    <xsl:template match="degree[count(./text()) > 0]">
        \ecvENR{Accquired qualifications}
                {\ecvBold{<xsl:value-of select="text()"/>}}
    </xsl:template>
    
    <xsl:template match="note[count(./text()) > 0]">
        \ecvENR{Notes}
                {<xsl:value-of select="text()"/>}
    </xsl:template>
    
    <xsl:template match="workexperiences[count(./*) > 0]">
        \ecvBSec{\hypertarget{hypertarget:\ecvJobs}{\ecvJobs}}
        <xsl:for-each select="work">
            \ecvEFR{Period}{<xsl:value-of select="from/text()"/>--<xsl:value-of select="to/text()"/>}
            \ecvENR{Employer}
                {\ecvBold{<xsl:value-of select="company/text()"/>}}
            \ecvENR{Position}{<xsl:value-of select="position/text()"/>}
            <xsl:if test="note[count(./text()) > 0]">
                \ecvENR{Main responsibilities}{<xsl:value-of select="note/text()"/>}
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>
